#!/usr/bin/env python
#-*- coding:utf-8 -*-
#by taobao ip_Library

import httplib2
import sys
import socket

try:
    scrpit, _url = sys.argv
except ValueError:
    print '...\n......\n\n没有获取到IP地址  退出程序!!!\n........Done!'
    sys.exit()

net_addr =  socket.getaddrinfo(_url, None)

url =  'http://ip.taobao.com/service/getIpInfo.php?ip=' + net_addr[0][4][0]
Hc = httplib2.Http('.cache')
resp, content = Hc.request(url, 'GET')

def vul_info(vule):
    return _ip_key['data'][vule]

def St_dic(arg):
    return eval(arg)

if resp['status'] == '200' or '302':

    if St_dic(content)['code'] == 0:
        conn =  content.decode('unicode_escape')
        _ip_key =  St_dic(conn)
        print vul_info('country'),vul_info('region'),vul_info('city'),vul_info('isp'),vul_info('ip')
    else:
         print St_dic(content)['data']
else:
    print '抱歉！服务不可用.',resp['status']